package com.luoqiz.demo.udpDemo;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Receiver {
	public static void main(String[] args) {
		DatagramSocket receiver=null;
		try {
			 receiver=new DatagramSocket(9999);
			System.out.println("接收方启动");
			byte[] buf=new byte[1024];
			DatagramPacket pack=new DatagramPacket(buf, buf.length);
			while(true) {
				receiver.receive(pack);
				System.out.print("收到消息：");
				System.out.println(new String(buf,0,pack.getLength()));
			}
			
		} catch (SocketException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			receiver.close();
		}
	}
}
